//
//  ChangePassWordViewController.m
//  JxCarios
//
//  Created by phev on 15/2/11.
//  Copyright (c) 2015年 xiongchuanqi. All rights reserved.
//

#import "ChangePassWordViewController.h"

@interface ChangePassWordViewController ()<UITextFieldDelegate>

@end

@implementation ChangePassWordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initAbout];
}

- (void)initAbout {
    self.title = @"修改密码";
    self.pswInputView.layer.borderColor =  UICOLOR_MAKE_RGB(239, 238, 244).CGColor;
    self.pswInputView.layer.cornerRadius = 0.8f;
    self.pswInputView.layer.masksToBounds = YES;
    [self showNavBarWithRightTitle:nil andRightAction:nil andLeftAction:nil andCustom:NO];

}

- (void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = YES;
    UIView *btn = (UIView *)[self.tabBarController.view  viewWithTag:400];
    btn.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = NO;
    UIView *btn = (UIView *)[self.tabBarController.view  viewWithTag:400];
    btn.hidden = NO;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string]; //得到输入框的内容
    if(toBeString.length <= 15){
        return YES;
    }else {
        return NO;
    }
    return YES;
}


- (IBAction)submitAction:(id)sender {
    if (_currenTextFeild.text.length == 0) {
        [self.navigationController.view makeToast:@"请输入当前密码" duration:1.5f position:TOP_POINT];
        return;
    }
    if (_currenTextFeild.text.length < 6) {
        [self.navigationController.view makeToast:@"密码长度不足六位" duration:1.5f position:TOP_POINT];
        return;
    }
    if (_xinPassWord.text.length == 0) {
        [self.navigationController.view makeToast:@"请输入新密码" duration:1.5f position:TOP_POINT];
        return;
    }
    if (_xinPassWord.text.length < 6) {
        [self.navigationController.view makeToast:@"密码长度不足六位" duration:1.5f position:TOP_POINT];
        return;
    }
    if (_affirmPassWord.text.length == 0) {
        [self.navigationController.view makeToast:@"请输入确认密码" duration:1.5f position:TOP_POINT];
        return;
    }
    if (_affirmPassWord.text.length < 6) {
        [self.navigationController.view makeToast:@"密码长度不足六位" duration:1.5f position:TOP_POINT];
        return;
    }
    if (![_xinPassWord.text isEqualToString:_affirmPassWord.text]) {
        [self.navigationController.view makeToast:@"两次密码输入不一致" duration:1.5f position:TOP_POINT];
        return;
    }
    if (!self.dataSource) {
        self.dataSource = [CurrentDataSource dataSourceWithRequestor:self];
    }
    self.dataSource.oldPwd =  _currenTextFeild.text;
    self.dataSource.xinPwd =  _xinPassWord.text;
    [self.dataSource changePassWord:^(id result) {
        [self.navigationController.view makeToast:@"修改成功" duration:1.5f position:TOP_POINT];
        [Common setLoginStatus:NO];
        [Common setAutoLogin:NO];
        
        [self.navigationController popViewControllerAnimated:YES];
    } andFail:^(id result) {
  
    }];
    
}
@end
